package com.example.demo.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;

/**
 * @author Liunh
 */
@Slf4j
public class ApplicationConstant {

    /**
     * 执行任务的线程数量
     */
    @Value("${app.scheduler.thread.count:10}")
    public int schedulerThreadCount;

    @Value("${spring.application.name}")
    public String applicationName;

    /**
     * NONE 不打印日志
     * MINIMUM 不打印请求消息体, 请求参数, 请求响应头
     * SIMPLE 打印精简的日志
     * ALL 打印所有日志
     */
    @Value("${app.performance.log:ALL}")
    public String performanceLogType;

    //@Value("${app.performance.log.ignore.urls:}")
    public String[] performanceLogIgnoreUrls;

    //@Value("${app.performance.log.ignore.sql:false}")
    public boolean performanceLogIgnoreSql;

    @Value("${spring.profiles.active:local}")
    public String profile;

    @Value("${app.okhttp.read.timeout:10000}")
    public long okHttpReadTimeout;

    @Value("${app.okhttp.connect.timeout:10000}")
    public long okHttpConnectTimeout;

    @Value("${app.okhttp.write.timeout:10000}")
    public long okHttpWriteTimeout;

    /**
     * 最大空闲连接数
     */
    @Value("${app.okhttp.max.idle:5}")
    public int okHttpMaxIdle;

    /**
     * 连接存活时间, 单位: 秒
     */
    @Value("${app.okhttp.alive.duration:300}")
    public int okHttpAliveDuration;


    public boolean isLocalProfile() {
        return StringUtils.isBlank(profile) || "LOCAL".equalsIgnoreCase(profile);
    }

    public boolean isDevProfile() {
        return "DEV".equalsIgnoreCase(profile);
    }

    public boolean isTestProfile() {
        return "TEST".equalsIgnoreCase(profile);
    }

    public boolean isPrevProfile() {
        return "PREV".equalsIgnoreCase(profile);
    }

    public boolean isProdProfile() {
        return "PROD".equalsIgnoreCase(profile);
    }

}
